package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.cy.dialog.BaseDialog;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.views.MultiLineRadioGroup;
import com.tencent.qcloud.tim.uikit.utils.ToastUtil;

/**
 * 支付选择弹框
 */
public class PayChooseDialog extends BaseDialog {
    //支付金额
    private TextView pay_money_contet;
    //微信、、支付宝
    private MultiLineRadioGroup rg_pay_type;
    private RadioButton radioButton;
    public PayChooseDialog(Context context) {
        super(context);
    }

    public PayChooseDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dialog_pay_choose);
        gravity(Gravity.BOTTOM);
        animType(BaseDialog.AnimInType.BOTTOM);
        //支付金额提示
        pay_money_contet = findViewById(R.id.pay_money_contet);
        //微信、、支付宝
        rg_pay_type = findViewById(R.id.rg_pay_type);
        rg_pay_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                radioButton = findViewById(i);
            }
        });
        radioButton = findViewById(R.id.radioButton_wechat);
        findViewById(R.id.confirm_pay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null != addItemOnClickListener){
                    if(null != radioButton){
                        if(radioButton.getId() == R.id.radioButton_wechat){
                            LogUtils.d("微信");
                            addItemOnClickListener.onSkipClicked(0,"微信");
                        }else if(radioButton.getId() == R.id.radioButton_Alipay){
                            LogUtils.d("支付宝");
                            addItemOnClickListener.onSkipClicked(1,"支付宝");
                        }
                    }else {
                        ToastUtils.make().show("请先选择支付方式");
                    }

                }
            }
        });
    }

    /**
     * 支付金额
     * @param payMoneyContet
     */
    public void setPayMoneyContet(String payMoneyContet){
        if(null == pay_money_contet){
            //支付金额提示
            pay_money_contet = findViewById(R.id.pay_money_contet);
        }
        pay_money_contet.setText(payMoneyContet);
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }



    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
